package cm.tl.pms.util;

import java.util.Random;

/**
 * @Author ZM
 * @Date 2020/4/17
 */
public class RandomUtil {
    private static final String ALL_CHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
    private static final String ALL_CHAR_ENGLISH = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String ALL_NUM = "0123456789";

    /**
     * 生成随机id
     *
     * @return
     */
    public static String getAllCharId(int size) {
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            sb.append(ALL_CHAR.charAt(random.nextInt(ALL_CHAR.length())));
        }
        return sb.toString();
    }


    public static String getAllCharEnglish(int size) {
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            sb.append(ALL_CHAR_ENGLISH.charAt(random.nextInt(ALL_CHAR_ENGLISH.length())));
        }
        return sb.toString();
    }

    public static String getAllNum(int size) {
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            sb.append(ALL_NUM.charAt(random.nextInt(ALL_NUM.length())));
        }
        return sb.toString();
    }
}
